<template>
  <div>
    <h1>app</h1>
    <input type="text" v-model="money" />
    <button @click="giveMoney">给多少钱</button>
    <child-one></child-one>
    <child-two></child-two>
  </div>
</template>

<script>
import ChildOne from "./components/ChildOne.vue";
import ChildTwo from "./components/ChildTwo.vue";
import pubSub from "pubsub-js";

export default {
  data() {
    return {
      money: "",
    };
  },
  methods: {
    giveMoney() {
      // console.log(this.money);
      // 发布
      pubSub.publish("getMoney", this.money);
    },
  },
  components: { ChildOne, ChildTwo },
};

/* 
使用pubsub-js
1 npm i pubsub-js
2 哪里需要传递消息（订阅发布），哪里引入pubsub-js库

3 订阅消息
pubSub.subscribe("事件名"，(msg,传递过来的消息)=>{
  // msg必须接收一下，否则报错
  console.log(msg);
})

4 哪里发布消息
pubSub.publish('事件名'，传递的参数)






*/
</script>

<style lang="scss" scoped>
</style>